package com.qf.ability.message.handler;

import com.ken.event.action.apply.producer.EventTemplate;
import com.qf.ability.message.entity.Message;
import com.qf.ability.message.handler.base.BaseInChannelHandler;
import com.qf.ability.message.utils.RoomUtils;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 停止课程
 * author Ken
 * create_time 2022/10/19
 */
@Component
@ChannelHandler.Sharable
@Slf4j
public class StopCourseMsgInChannelHandler extends BaseInChannelHandler<Message> {

    @Override
    protected boolean isSupport(Message msg) {
        return msg.getId().equals("stopCourse");
    }

    @Override
    protected void hander(ChannelHandlerContext ctx, Message msg) {
        //课程id
        Integer cid = msg.getCid();

        //删除课程的相关信息
        RoomUtils.remove(cid);

        //修改当前课程id的内容
        EventTemplate.sendQuickly("courseStop", cid);
    }
}
